package org.abratuhi.kvngroupware.pubsub;

public class PubSubTest {
	
	public static void main(String[] args){
		IntegerValue reference = new IntegerValue(10);
		String[] attributes = new String[]{"attr1", "attr2"}; 
		String[] subscriberIds = new String[]{"id1", "id2", "id3"};
		PubsubManager<Integer> manager = new PubsubManager<Integer>(attributes, reference);
		
		int nSubscriptions = 100;
		Subscription<Integer>[] subscriptions = new Subscription[nSubscriptions];
		
		for(int i=0; i<nSubscriptions; i++) {
			subscriptions[i] = new Subscription<Integer>(subscriberIds[0]);
			for(int j=0; j<attributes.length; j++)
				subscriptions[i].addAttribute(attributes[j], new Range<Integer>(new IntegerValue(random(1,50)), new IntegerValue(random(50,100))));
		}
		
		//for(int i=0; i<nSubscriptions; i++)
		//	System.out.println(subscriptions[i].toString());
		
		for(int i=0; i<nSubscriptions; i++)
			manager.addSubscription(subscriptions[i]);
		
		for(int i=0; i<manager.hubs.size(); i++){
			Hub<Integer> h = manager.hubs.get(attributes[i]);
			System.out.println("HUB ["+h.attributeId+"]:");
			for(int j=0; j<h.hubnodes.size(); j++){
				Hubnode<Integer> hn = h.hubnodes.get(j);
				System.out.println(hn.toString());
				for(int k=0; k<hn.subscriptions.size(); k++){
					Subscription<Integer> s = hn.subscriptions.get(k);
					System.out.println(s.toString());
				}
			}
		}
	}
	
	public static int random(int v1, int v2){
		return (int) (Math.random()*(v2-v1)+v1);
	}
}
